package com.example.baserecyclerviewadapterdemo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.example.baserecyclerviewadapterdemo.R;
import com.example.baserecyclerviewadapterdemo.activity.node.NodeAdapterActivity;
import com.example.baserecyclerviewadapterdemo.adapter.HomeAdapter;
import com.example.baserecyclerviewadapterdemo.entity.HomeEntity;

import java.util.Arrays;
import java.util.List;


public class HomeActivity extends AppCompatActivity implements OnItemClickListener {

    private HomeAdapter homeAdapter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        homeAdapter = new HomeAdapter(R.layout.home_item_view,getHomeItemData());
        homeAdapter.setAnimationEnable(false);
        View top = getLayoutInflater().inflate(R.layout.top_view,recyclerView,false);
        homeAdapter.addHeaderView(top);
        homeAdapter.setOnItemClickListener(this);
        recyclerView.setAdapter(homeAdapter);
    }

    @Override
    public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        HomeEntity homeEntity = (HomeEntity) adapter.getData().get(position);
        startActivity(new Intent(HomeActivity.this,homeEntity.getActivity()));
    }

    private List<HomeEntity> getHomeItemData(){
        return Arrays.asList(
                new HomeEntity("Animation", AnimationUseActivity.class, R.mipmap.gv_animation),
                new HomeEntity("Header/Footer",HeaderAndFooterUseActivity.class,R.mipmap.gv_header_and_footer),
                new HomeEntity("EmptyView",EmptyViewUseActivity.class,R.mipmap.gv_empty),
                new HomeEntity("ItemClick",ItemClickActivity.class,R.mipmap.gv_item_click),
                new HomeEntity("DiffUtil",DiffUtilActivity.class,R.mipmap.gv_databinding),
                new HomeEntity("MultiItem",MultiItemActivity.class,R.mipmap.gv_multipleltem),
                new HomeEntity("Quick Section",QuickSectionActivity.class,R.mipmap.gv_section),
                new HomeEntity("NodeAdapterUse", NodeAdapterActivity.class,R.mipmap.gv_expandable),
                new HomeEntity("LoadMore",LoadMoreRefreshActivity.class,R.mipmap.gv_pulltorefresh)
        );
    }
}
